<template>
  <!-- 余额变动明细 余额明细 -->
  <div class="app-container bgf radius" v-loading="loading">
    <el-form :model="queryParams" ref="queryForm" class="zdy-form search-form-new" :inline="true" label-width="auto">
      <div class="search-box">
        <el-form-item label="用户" prop="userId">
          <virtual-select
            v-model="queryParams.userId"
            :list="allUsers"
            label="nickName"
            value="userId"
            :placeholder="'输入关键字用于搜索买家'"
            :keeps-params="20"
            :is-concat="false"
            :concat-symbol="' || '"
            :is-multiple="false"
            :disabled="false"
            :allow-create="false"
          />
        </el-form-item>
        <el-form-item label="变动类型" prop="changeType">
          <el-select
            v-model="queryParams.changeType"
            placeholder="请选择变动类型"
            clearable
          >
            <el-option
              v-for="(dict, key) in commonMaps.moneyChangeTypeMap"
              :key="key"
              :label="dict.label"
              :value="key"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="时间" prop="">
          <el-date-picker
              style="width: 300px"
              v-model="timer"
              type="daterange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              :picker-options="pickerOptions"
              @change="handleQuery"
            >
            </el-date-picker>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh"  @click="resetQuery">重置/刷新</el-button>
        </el-form-item>
      </div>
    </el-form>
    <div style="height:calc(100vh - 260px)">
      <!-- <userMoneyChangeList :listData="tableData.records"></userMoneyChangeList> -->
    </div>
    
    <!-- <el-table
        :data="tableData.records"
        height="calc(100vh - 330px)"
        style="width: 100%"
      >
      <el-table-column
          prop="userName"
          label="用户"
          min-width="100"
        ></el-table-column>

        <el-table-column
          prop="createTime"
          label="时间"
          width="160"
        ></el-table-column>
        <el-table-column prop="" label="变动类型" width="120">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.changeType?commonMaps.moneyChangeTypeMap[scope.row.changeType].type:'warning'"
              >{{
                scope.row.changeType?commonMaps.moneyChangeTypeMap[scope.row.changeType].label:'无'
              }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="state" label="余额变动" width="120">
          <template slot-scope="scope">
            <div>
              {{ `${scope.row.type == 1 ? "+" : "-"}${scope.row.amount}` }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="afterAmount"
          label="变动后余额"
          width="120"
        ></el-table-column>

        <el-table-column
          prop="reason"
          label="说明"
          min-width="120"
          show-overflow-tooltip
        >
          
        
        </el-table-column>
      </el-table> -->

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>
<script>
import myMoneyApi from "@/api/financeCenter/myMoney.js";
import supplyConfigApi from "@/api/system/supplyConfig"
import VirtualSelect from "@/components/VirtualSelect.vue";
// import userMoneyChangeList from "@/views/financialWorkbench/components/userMoneyChangeList.vue"
export default {
  name: "",
  components:{VirtualSelect},
  data() {
    return {
      loading:false,
      timer:[],
      tableData:{
        records:[],
        
      },
      total:0,
      allUsers:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        applicantTimeStart: "",
        applicantTimeEnd: "",
        dataType: "all",
        userId:'',
        changeType:''
      },
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    this.getList()
    this.getAllUserList()
  },
  methods: {
    // 获取列表
    getList() {
      // queryParams 请求列表
      this.loading = true;
      
      if (this.timer && this.timer.length == 2) {
        this.queryParams.operatorTimeStart = this.timer[0] + " 00:00:00";
        this.queryParams.operatorTimeEnd = this.timer[1] + " 23:59:59";
      } else {
        this.queryParams.operatorTimeStart = "";
        this.queryParams.operatorTimeEnd = "";
      }
      myMoneyApi.getList(this.queryParams).then((res) => {
        this.loading = false;
        this.tableData.records = res.rows;
        this.total = res.total;
      });
    },
    // 所有用户
    getAllUserList(val) {
      supplyConfigApi.getAllUserList().then(res => {
        this.allUsers = res.rows
      })
    },

   
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams={
        pageNum: 1,
        pageSize: 20,
        applicantTimeStart: "",
        applicantTimeEnd: "",
        dataType: "all",
        userId:'',
        changeType:''
      },
      this.timer = []
      this.handleQuery();
    },
   

    // 每页条数改变
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.getList();
    },
    // 页码改变
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getList();
    },
  }
};
</script>
<style lang="scss" scoped>
  .app-container{
    .search-box{
      position: relative;
      .tip{
        position: absolute;
        color: red;
        right: 50px;
      }
    }
  }
</style>
